/*
 * MainWindow.java
 * Copyright (C) 2007 Ezequiel Turovetzky
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
package ar.com.botonera.gui;

import javax.swing.JFrame;
import javax.swing.JMenuBar;

import ar.com.botonera.Botonera;
import ar.com.botonera.config.BotoneraManager;
import ar.com.botonera.config.Configuration;
import ar.com.botonera.config.Configurator;
import ar.com.botonera.gui.common.ImageLoader;
import ar.com.botonera.gui.common.listeners.BotoneraWindowAdapter;
import ar.com.botonera.gui.menu.BotoneraMenu;

/**
 * Ventana principal de la aplicaci&oacute;n.
 * <br><br>Usa las properties:
 * <ul>
 * <li><code>ar.com.botonera.main.window.title</code></li>
 * <li><code>ar.com.botonera.main.window.width</code></li>
 * <li><code>ar.com.botonera.main.window.height</code></li>
 * </ul>
 * @author <a href="mailto:tezequiel@gmail.com">Ezequiel Turovetzky</a>
 * @version 1.0
 */
public class MainWindow extends JFrame {

    //~ Instance fields --------------------------------------------------------

    /** La botonera */
    private JBotonera botonera;

    //~ Constructors -----------------------------------------------------------

    /**
     * Crea una nueva instancia de esta clase.
     */
    public MainWindow() {
    	botonera = new JBotonera();
    	setTitle(BotoneraManager.getInstance().get("ar.com.botonera.main.window.title"));
        setIconImage(ImageLoader.loadImage("images/botonera.png"));
        setResizable(false);
        setDefaultCloseOperation(HIDE_ON_CLOSE);
        setJMenuBar(new JMenuBar());
        
        addWindowListener(new BotoneraWindowAdapter());
    }

    //~ Methods ----------------------------------------------------------------
    
    /**
     * Agrega la botonera, la barra de men&uacute; e invoca
     * <b><code>super.pack()</code></b>. Luego, establece la dimensi&oacute;n
     * a partir de las properties:
     * <ul>
     * <li><code>ar.com.botonera.main.window.width</code>, para el ancho.</li>
     * <li><code>ar.com.botonera.main.window.height</code>, para el alto.</li>
     * </ul>
     */
    @Override
    public void pack() {
        getContentPane().add(botonera);
        getJMenuBar().add(new BotoneraMenu());
        super.pack();
        
        Configuration cfg = Configurator.getInstance().getConfiguration();
        setSize(cfg.getWindowWidth(), cfg.getWindowHeight());
    }

    /**
     * Abre la ventana.
     */
    public void open() {
        pack();
        setVisible(true);
    }
    
    /**
     * Devuelve una referencia a la botonera de la aplicaci&oacute;n.
     * @return Una referencia a la botonera de la aplicaci&oacute;n
     */
	public Botonera getBotonera() {
		return botonera;
	}
}